<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title></title>
  </head>
  <body>
    <div id="app">
      <div>姓：<input type="text" v-model="firstName" /></div>
      <div>名：<input type="text" v-model="lastName" /></div>
      <div>全名：<span>{{ fullName }}</span></div>
      <div>可写全名：<span>{{ fullNameWrite }}</span></div>
    </div>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

    <script>
      const { createApp, computed, ref } = Vue;

      const app = createApp({
        setup() {
          const firstName = ref("");
          const lastName = ref("");

          const fullName = computed(() => {
            return firstName.value + " " + lastName.value;
          });

          const fullNameWrite = computed({
            get() {
              return firstName.value + " " + lastName.value;
            },
            set(newVal) {
              [firstName.value = "", lastName.value = ""] = newVal.split(" ");
            },
          });

          //   fullName.value = "编程 段子"; // WRIN: computed value is readonly
          fullNameWrite.value = "编程 段子"; // OK

          return {
            firstName,
            lastName,
            fullName,
            fullNameWrite,
          };
        },
      });

      app.mount("#app");
    </script>
  </body>
</html>
